package com.lfnyxy.service.imp;

import com.lfnyxy.dao.ConfigurationDao;
import com.lfnyxy.entity.ConfigurationEntity;
import com.lfnyxy.query.ConfigurationQuery;
import com.lfnyxy.service.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConfigurationServiceImp implements ConfigurationService {
    @Autowired
    public ConfigurationDao configurationDao;

    public int CreateItem(ConfigurationEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return configurationDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(ConfigurationEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return configurationDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List <ConfigurationEntity> QueryPageList(ConfigurationQuery query) {
        int count = configurationDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return configurationDao.QueryPageList(query);
        }
        return null;
    }

    public List <ConfigurationEntity> QueryAll() {
        return configurationDao.QueryAll();
    }

    public ConfigurationEntity QueryItem(int Id) {
        if (Id > 0) {
            return configurationDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return configurationDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(ConfigurationEntity entity) {
        if (entity != null) {
            return configurationDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}